package com.pmcc.core.entity.security;


import com.fasterxml.jackson.annotation.JsonIgnore;
import com.pmcc.core.entity.UUIDEntity;

import javax.persistence.Column;
import javax.persistence.MappedSuperclass;
import javax.persistence.PrePersist;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.Date;

/**
 * Created by syk on 17/6/23.
 */
@MappedSuperclass
public abstract class Authenticatable extends UUIDEntity {
    /**
     * passphrase value
     */
    @Size(min = 4, max = 100)
    @JsonIgnore
    private String password;

    /**
     * salt value in hex
     */
    @Column(length = 120)
    @JsonIgnore
    protected String salt;

    /**
     * The timestamp that last successfully login
     */
    @Column(nullable = false, length = 120)
    protected Date lastLoginDate;

    /**
     * The time that this guy registered, the value is immutable
     */
    @Column(nullable = false, updatable = false)
    protected Date registerDate;

    /**
     * indicate whether the entity need to change its password on login
     */
    @Column()
    protected boolean needChangePassword;

    /**
     * 账户是否可以用.
     *
     * 用于封禁账户或类似功能
     */
    @Column(nullable = true)
    protected boolean enabled;

    @javax.persistence.Temporal(TemporalType.TIMESTAMP)
    private Date lastPasswordResetDate;

    /**
     * Setup when the entity been created.
     *
     * We setup the registerDate here.
     */
    @PrePersist
    private void setup() {
        this.registerDate = new Date();
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Date getLastPasswordResetDate() {
        return lastPasswordResetDate;
    }

    public void setLastPasswordResetDate(Date lastPasswordResetDate) {
        this.lastPasswordResetDate = lastPasswordResetDate;
    }

    public String getSalt() {
        return this.salt;
    }

    public void setSalt(String salt) {
        this.salt = salt;
    }



    public Date getLastLoginDate() {
        return lastLoginDate;
    }

    public void setLastLoginDate(Date lastLoginDate) {
        this.lastLoginDate = lastLoginDate;
    }

    public Date getRegisterDate() {
        return registerDate;
    }

    public void setRegisterDate(Date registerDate) {
        this.registerDate = registerDate;
    }

    public boolean isNeedChangePassword() {
        return needChangePassword;
    }

    public void setNeedChangePassword(boolean needChangePassword) {
        this.needChangePassword = needChangePassword;
    }

    public boolean getEnabled() {
        return enabled;
    }

    public void setEnabled(boolean enabled) {
        this.enabled = enabled;
    }

}
